package com.biz.primus.ms.stock.api;

import com.biz.primus.base.vo.BaseStockRespVo;
import com.biz.primus.base.vo.StockRespVo;
import com.biz.primus.common.enums.StockChannelEnum;
import com.biz.primus.common.vo.SpringPageVO;
import com.biz.primus.model.stock.vo.*;
import com.biz.primus.ms.stock.service.StockChangeLogService;
import com.biz.primus.ms.stock.service.StockService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author JKLiues
 * @date 2017/10/21
 */
@RestController
@RequestMapping("soa/stockService")
@Api("库存服务接口")
public class StockApiController {

    private final StockService stockService;
    private final StockChangeLogService stockChangeLogService;


    @Autowired
    public StockApiController(StockService stockService, StockChangeLogService stockChangeLogService) {
        this.stockService = stockService;
        this.stockChangeLogService = stockChangeLogService;
    }

    @ApiOperation(value = "库存全量接口")
    @PostMapping(value = "saveStockAll")
    public void saveDepotStocks(@RequestBody List<AllStockItemVo> reqVos) {
        stockService.saveDepotStocks(reqVos);
    }

    @ApiOperation("全量库存后置操作")
    @PostMapping("afterHandleStockAll")
    public void afterHandleStockAll(StockChannelEnum channelCode) {
        stockService.afterHandleStockAll(channelCode);
    }

    @ApiOperation(value = "库存更新", notes = "只改库存，不改锁库存")
    @PostMapping(value = "updateStockOnly")
    public void updateStockOnly(@RequestBody IncrDepotStockReqVo reqVo) {
        stockService.updateStockOnly(reqVo);
    }

    @ApiOperation(value = "锁库存更新", notes = "只改锁库存，不改库存")
    @PostMapping(value = "updateLockedStockOnly")
    public void updateLockedStockOnly(@RequestBody IncrDepotStockReqVo reqVo) {
        stockService.updateLockedStockOnly(reqVo);
    }

    @ApiOperation(value = "库存和锁库存同时更新", notes = "改库存的同时改锁库存")
    @PostMapping(value = "updateStockAndLockedStock")
    public void updateStockAndLockedStock(@RequestBody IncrDepotStockReqVo reqVo) {
        stockService.updateStockAndLockedStock(reqVo);
    }

    @ApiOperation(value = "批量获取商品库存")
    @PostMapping(value = "getDepotStockInBatch")
    public List<StockRespVo> getDepotsStockInBatch(@RequestBody StocksReqVo reqVo) {
        return stockService.getDepotStockInBatch(reqVo);
    }

    @ApiOperation(value = "获取指定门店附近满足库存的门店")
    @PostMapping(value = "getNearMeetStockDepots")
    public List<DepotMeetStockRespVo> getNearMeetStockDepots(@RequestBody NearMeetStockDepotReqVo reqVo) {
        return stockService.getNearMeetStockDepots(reqVo);
    }

    @ApiOperation(value = "获取省内满足商品库存的门店")
    @PostMapping(value = "getMeetByProvince")
    public MeetStockRespVo getMeetByProvince(@RequestBody ProvinceStockReqVo reqVo) {
        return stockService.getMeetByProvince(reqVo);
    }

    @ApiOperation(value = "获取立即送满足商品库存的门店")
    @PostMapping(value = "getMeetStock")
    public MeetStockRespVo getMeetStock(@RequestBody ProvinceStockReqVo reqVo) {
        return stockService.getMeetStock(reqVo);
    }

    @ApiOperation(value = "获取太原店内满足商品库存且数量最多的门店")
    @PostMapping(value = "getMeetByHome")
    public MeetStockRespVo getMeetByHome(@RequestBody MeetHomeStockReqVo reqVo) {
        return stockService.getMeetByHome(reqVo);
    }

    @ApiOperation(value = "获取总仓库存")
    @PostMapping(value = "getCenterStock")
    public List<BaseStockRespVo> getCenterStock(@RequestBody BaseStockReqVo reqVo) {
        return stockService.getCenterStock(reqVo);
    }

    @ApiOperation(value = "获取太原店库存")
    @PostMapping(value = "getHomeStock")
    public List<BaseStockRespVo> getHomeStock(@RequestBody BaseStockReqVo reqVo) {
        return stockService.getHomeStock(reqVo);
    }

    @ApiOperation(value = "后台查询库存列表", notes = "返回列表，由前端完成分页")
    @PostMapping(value = "backenStockList")
    public List<BackenStockListRespVo> backenStockList(@RequestBody BackenStockListReqVo reqVo) {
        return stockService.backenStockList(reqVo);
    }

    @ApiOperation("后台查询库存变更列表")
    @PostMapping(value = "logPageResult")
    public SpringPageVO<StockChangeLogRespVo> logPageResult(@RequestBody StockChangeLogListReqVo reqVo) {
        return stockChangeLogService.pageResult(reqVo);
    }

}
